<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html>
<html>
<head>
	<title>供货协议-编辑供货协议</title>
	<meta charset="utf-8">
	<link rel="stylesheet" type="text/css" href="<%=basePath %>libs/bootstrap-3.3.7-dist/css/bootstrap.min.css">
	<link rel="stylesheet" type="text/css" href="<%=basePath %>css/reset.css">
	<link rel="stylesheet" type="text/css" href="<%=basePath %>css/style.css">
	<link rel="stylesheet" type="text/css" href="<%=basePath %>css/iframe.css">
</head>
<body>
	<div id="mainContent">
		<div id="mainContent_content">
			<div class="page_header"><label id="topNav"><a href="<%=basePath %>supplyagreement/paginglist.do">供货协议</a>&nbsp;&gt;&gt;&nbsp;<a>编辑供货协议</a></label>
				<a href="<%=basePath %>supplyagreement/paginglist.do" class="return r"><img src="<%=basePath %>images/unreturn.png"></a></div>
			
			
<!-- 			<div class="btn rightBtn">
				<input type="button" value="新建" disabled="disabled"></input>
				<input type="button" value="复制" disabled="disabled"></input>
				<input type="button" value="保存"></input>
				<input type="button" value="删除"></input>
			</div> -->
			<form id="update_supply_agreement_form">
			<div class="box formBox">
				<input type="hidden" name="supplyagreementid" value="${supplyagreement.supplyagreementid }" class="form-control">
				<input type="hidden" name="supplierid" value="${supplyagreement.supplierid }" class="form-control">
				<p>
						<label>协议代码</label>
						<input type="text" readonly value="${supplyagreement.protocolcode }" class="form-control"></input>
						<label>供应商</label>
						<input type="text" readonly value="${supplyagreement.suppliercode }" class="form-control"></input>
						<input type="text" readonly value="${supplyagreement.suppliername }" class="form-control"></input>
					<!-- <label>
						<span>邮轮</span>
						<input type="text"></input>
					</label> -->
				</p>
				<p>
						<label>说明</label>
						<input type="text" name="protocolexplain" value="${supplyagreement.protocolexplain }" class="form-control"></input>
						<label>协议时间</label>
						<input type="text" name="starttimestr" value="<fmt:formatDate value='${supplyagreement.starttime }' type='date'/>" readonly onclick="WdatePicker({skin:'whyGreen',dateFmt:'yyyy-MM-dd'})" class="form-control"></input>
						<label class="dateSpan">至</label>
						<input type="text" name="endtimestr" value="<fmt:formatDate value='${supplyagreement.endtime }' type='date'/>" readonly onclick="WdatePicker({skin:'whyGreen',dateFmt:'yyyy-MM-dd'})" class="form-control"></input>
	<!-- 				<label class="checkBox">
						<input type="checkbox"></input>
						<span class="span">是否为IMPA物料?</span>
					</label> -->
				</p>
			</div>
			<div class="tableBox box">
				<table class="table table-bordered table_text_center">
					<thead>
						<tr>
							<th>物品代码</th>
							<th>物品名称</th>
							<th>物品条码</th>
							<th>单位</th>
							<th>采购单价</th>
							<th>操作</th>
						</tr>
					</thead>
					<tbody id="hasAddItemTbody">
						<c:forEach items="${s_iteminfolist}" var="s_iteminfo" varStatus="i">
							<tr>
								<td>${s_iteminfo.itemcode }</td>
								<td>${s_iteminfo.chinesename }</td>
								<td>${s_iteminfo.articlebarcode }</td>
								<td>${s_iteminfo.salesunit }</td>
								<td>
								<input type="text" name="itemPrice" value="${s_iteminfo.purchaseprice }" />
								<input type="hidden" name="itemIds" value="${s_iteminfo.iteminformationid }" />
								</td>
								<td><a onclick="deleteIteminfo(this);">删除</a></td>
							</tr>
						</c:forEach>
					</tbody>
				</table>
				<div class="btn rightBtn" style="text-align:right;width:98%;">
					<a onclick="downloadAgreementAnnex(${supplyagreement.supplyagreementid });" class="l">下载附件:${supplyagreement.protocoenclosure }</a>
					<c:if test="${isEdit }">					
								<span>上传附件:</span>
								<a id="supplyAgreementAnnexName" style="width:580px;text-align:left;color:#2b7dbc;cursor:pointer;">选择文件</a>
								<input type="file" style="display:none;" id="supplyAgreementAnnex" name="supplyagreementannex" onchange="chooseAnnex();"></input>

						<input type="button" value="添加物品" onclick="toAddSupplyAgreementItem();" class="btn btn1"></input>
						<input type="button" value="保存" onclick="saveEditSupplyAgreement();" class="btn btn1"></input>
					</c:if>
					<input type="button" value="退出" onclick="location.href='<%=basePath %>supplyagreement/paginglist.do'" class="btn btn1"></input>
				</div>
			</div>
			</form>
			<div class="box updateBox">
				<p>
						<label>创建时间</label>
						<input type="text" readonly value="<fmt:formatDate value='${supplyagreement.createdate }' type='date'/>" class="form-control"></input>
						<label>最后处理时间</label>
						<input type="text" readonly value="<fmt:formatDate value='${supplyagreement.lastprocessingtime }' type='date'/>" class="form-control"></input>
				</p>
				<p>
						<label>创建人</label>
						<input type="text" readonly value="${supplyagreement.createpersonname }" class="form-control"></input>
						<label>最后处理人</label>
						<input type="text" readonly value="${supplyagreement.lastpersonname }" class="form-control"></input>
				</p>
			</div>
		<jsp:include page="/jsp/basicData/supplyAgreement/addSupplyAgreementItem.jsp"></jsp:include>
		<jsp:include page="/jsp/basic/prompt.jsp"></jsp:include>
		</div>
	</div>
	<script src="<%=basePath %>js/jquery-3.2.1.min.js"></script>
	<script src="<%=basePath %>libs/bootstrap-3.3.7-dist/js/bootstrap.js"></script>
	<script src="<%=basePath %>libs/bootstrap-table-master/dist/bootstrap-table.js"></script>
	<script src="<%=basePath %>libs/bootstrap-table-master/dist/locale/bootstrap-table-zh-CN.min.js"></script>
	<script src="<%=basePath %>My97DatePickers/WdatePicker.js"></script>
	<script src="<%=basePath %>js/public.js"></script>
	<script type="text/javascript">
	function downloadAgreementAnnex(supplyagreementid){
		window.open("<%=basePath %>supplyagreement/fileDownload.do?supplyagreementid="+supplyagreementid);
	}
	
	function addToHasAddTable(item){
		var html="<tr>";
		html+="<td>"+item.itemcode+"</td>";
		html+="<td>"+item.chinesename+"</td>";
		html+="<td>"+item.articlebarcode+"</td>";
		html+="<td>"+item.salesunit+"</td>";
		html+="<td><input type='text' name='itemPrice' value='' />";
		html+="<input type='hidden' name='itemIds' value='"+item.iteminformationid+"' /></td>";
		html+="<td><a onclick='deleteIteminfo(this);'>删除</a></td>";
		html+="</tr>";
		$("#hasAddItemTbody").append(html);
	}
	
	function deleteIteminfo(obj){
		$(obj).parent().parent().remove();
	}
	
	function saveEditSupplyAgreement(){
		
		if(!validateAddForm()) return ;//校验
		
		$.ajax({
			url:"<%=basePath %>supplyagreement/update.do",
			type:"post",
			async : false,
			dataType:"json",
	        contentType: false,  
	        processData: false,  
			data : new FormData($("#update_supply_agreement_form")[0]),
			success:function(data){
				if(data.result=="success"){
					Prompt.alert("提示","供货协议保存成功",Prompt.refresh);
				}else{
					
				}
			},
			error :function(){
				Prompt.alert("提示","修改供货协议失败！");
			}
		});
	}
	
	function chooseAnnex(){
		var annex=$("#supplyAgreementAnnex").val();
		var arr=annex.split('\\');
	    var fileName=arr[arr.length-1];
		if(annex==""){
			$("#supplyAgreementAnnexName").html("选择文件")
		}else{
			$("#supplyAgreementAnnexName").html(fileName)
		}
	}
	
	//编辑时间文本框保存信息
	function validateAddForm(){
		if(!validateString("协议时间","#update_supply_agreement_form [name='starttimestr']",120,false)){
			return false;
		} 
		
		if(!validateString("协议时间","#update_supply_agreement_form [name='endtimestr']",120,false)){
			return false;
		} 
		return true;
	}
	</script>
</body>
</html>